package com.cocolover2.andbase.mvpbase;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;


/**
 *
 * @param <V>代表view接口
 */
public abstract class AppBasePresenter<V extends ImvpBaseView> {
    protected Reference<V>mViewRef;

    public void attachView(V view){         //建立关联
        mViewRef=new WeakReference<V>(view);
    }

    protected V getView(){
        return mViewRef.get();
    }

    public boolean isViewAttached(){
        return mViewRef!=null && mViewRef.get()!=null;
    }

    //该方法在activity或者Fragment的onDestory中调用
    public void detachView(){
        if(mViewRef!=null){
            mViewRef.clear();
            mViewRef=null;
        }
    }
}
